using Digitalmes.Application.Mes.Processes.StepStandards;
using Digitalmes.Application.Mes.Processes.StepStandards.Commands;
using Digitalmes.Application.Mes.Processes.StepStandards.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Processes;

/// <summary>
/// 工艺标准终结点。
/// </summary>
public sealed class StepStandardEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/process", "stepStandard")
            .RequireAuthorization()
            .MapGet(GetStepStandardListAsync, "list")
            .MapPost(CreateStepStandardAsync)
            .MapPut(UpdateStepStandardAsync, "{id}")
            .MapDelete(DeleteStepStandardAsync, "{id}");
    }

    [EndpointDescription("查询工艺标准集合")]
    public async Task<IApiResult> GetStepStandardListAsync(ISender sender, [AsParameters] GetStepStandardListQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("分页查询工艺标准")]
    public async Task<IApiResult> CreateStepStandardAsync(ISender sender, ProcStepStandardDto dto)
    {
        var result = await sender.Send(new CreateStepStandardCommand(dto));
        return result.ToApiResult();
    }

    [EndpointDescription("更新工艺标准")]
    public async Task<IApiResult> UpdateStepStandardAsync(ISender sender, long id, ProcStepStandardDto dto)
    {
        var result = await sender.Send(new UpdateStepStandardCommand(id, dto));
        return result.ToApiResult();
    }

    [EndpointDescription("删除工艺标准")]
    public async Task<IApiResult> DeleteStepStandardAsync(ISender sender, long id)
    {
        var result = await sender.Send(new DeleteStepStandardCommand(id));
        return result.ToApiResult();
    }
}
